import UIKit

func doWork(block: () -> Void) {
  block()
}

doWork {
  print("work")
}

func doWorkAsync(block: @escaping () -> Void) {
  DispatchQueue.main.async {
    block()
  }
}

class S {
  var foo = "foo"

  func method1() {
    doWork {
      print(foo)
    }
    foo = "bar"
  }

  func method2() {
    doWorkAsync {
			print(self.foo)
    }
    foo = "bar"
  }

  func method3() {
    doWorkAsync {
      [weak self] in
      print(self?.foo ?? "nil")
    }
    foo = "bar"
  }
}

S().method1() // foo
S().method2() // bar”
S().method3() // nil
